from ..extensions import db

class BfUser(db.Model):
    __bind_key__ = 'jys'
    id=db.Column(db.Integer,primary_key=True,autoincrement=True)
    username=db.Column(db.String(50),nullable=False,comment='用户名')
    mobile=db.Column(db.String(50),unique=True,default='',comment='手机号码')
    mobiletime=db.Column(db.Integer,nullable=False,default='',comment='手机号创建或跟新时间')
    password=db.Column(db.String(64),nullable=False,comment="密码")
    tpwdsetting=db.Column(db.String(32),default='',comment='密码的设置')
    paypassword=db.Column(db.String(50),nullable=False,default='',comment='交易密码')
    invit_1=db.Column(db.String(50),nullable=False,default='',comment='邀请等级')
    invit_2=db.Column(db.String(50),nullable=False,default='',comment='邀请等级2(子邀请)')
    invit_3=db.Column(db.String(50),nullable=False,default='',comment='邀请等级3(子子邀请)')
    truename=db.Column(db.String(32),nullable=False,default='',comment='真实姓名')
    idcard=db.Column(db.String(32),default='',comment='身份证')
    logins=db.Column(db.Integer,default=0,nullable=False,comment='登陆次数')
    ga=db.Column(db.String(50),nullable=False,default='')
    addip=db.Column(db.String(50),nullable=False,default='',comment='登录IP')
    addr=db.Column(db.String(50),nullable=False,default='',comment='登录地址')
    sort=db.Column(db.Integer,default=0,nullable=False,comment='排序')
    addtime=db.Column(db.Integer,default=0,nullable=False,comment='创建时间')
    endtime=db.Column(db.Integer,default=0,nullable=False,comment='结束时间')
    status=db.Column(db.Integer,default=0,nullable=False,comment='状态')
    email=db.Column(db.String(50),default=None,comment="邮箱")
    alipay=db.Column(db.String(50),default=None,comment='支付宝')
    invit=db.Column(db.String(50),default=None,comment='邀请码')
    token=db.Column(db.String(50),default=None,comment='激活token')
    mibao_question=db.Column(db.String(200),default=None,comment='密保问题')
    mibao_answer=db.Column(db.String(200),default=None,comment='密保答案')
    zhengjian=db.Column(db.String(50),default=None,comment='证件类型')#省份证的话,填写sfz
    idcard_zheng=db.Column(db.String(200),default=None,comment='证件正面照片')
    idcard_fan=db.Column(db.String(200),default=None,comment='证件反面照片')
    findpwd_mibao=db.Column(db.Integer,default=0,comment='找回密码')
    findpaypwd_mibao=db.Column(db.Integer,default=0,comment='找回支付密码')
    is_agree=db.Column(db.Integer,default=0,comment='0是未进行同意操作（默认） 1是已经同意')
    idcard_shouchi=db.Column(db.String(200),default=None,comment='手持证件照片')
    ethpassword=db.Column(db.String(50),default=None,comment='以太坊密码')
    etcpassword=db.Column(db.String(50),default=None,comment='etc密码')
    pwd_err=db.Column(db.String(50),default=0,nullable=False,comment='登陆密码错误次数')
    #相当于DECIMAL（10,8）
    # buy_sum=db.Column(db.Numeric(precision=8, asdecimal=False, decimal_return_scale=None),default=0,comment='买入数量')
    buy_sum=db.Column(db.Numeric(20,5),default=0,comment='场外买入数量')
    sell_sum = db.Column(db.Numeric(20, 5), default=0, comment='场外卖出数量')
    cpcprize_sum=db.Column(db.Integer,default=0,comment='')
    trade_sum=db.Column(db.Numeric(20,5),default=0,comment='场外交易总数量')
    gjcode=db.Column(db.Integer,default=86,comment='',nullable=False)
    enname=db.Column(db.String(50),default=None,comment='')
    headimg=db.Column(db.String(50),default=None,comment='头像图片')
    goodnum=db.Column(db.Integer,default=0,comment='',nullable=False)
    goodcomm=db.Column(db.Integer,default=0,comment='',nullable=False)
    jianjie=db.Column(db.String(200),default=None,comment='个人简介')
    history=db.Column(db.Numeric(20,5),default=0,comment='历史')
    sftime_sum=db.Column(db.Integer,default=0,comment='',nullable=False)
    first_trade_time=db.Column(db.Integer,default=0,comment='',nullable=False)
    transact=db.Column(db.Integer,default=0,comment='',nullable=False)
    xinren=db.Column(db.Text,comment='')
    pingbi=db.Column(db.Text,comment='')
    ixinren=db.Column(db.Text,comment='')
    ipingbi=db.Column(db.Text,comment='')
    trade_id=db.Column(db.Text,comment='')
    grade=db.Column(db.Integer,default=3,comment='等级')
    cpcpassword=db.Column(db.String(100),default=None,comment='个人简介')
    marketid=db.Column(db.String(100),default=None,comment='收藏币种的列表')
    socket_token=db.Column(db.String(32),default='',comment='')
    login_time=db.Column(db.Integer,default=0,comment='登陆时间')
    user_coin = db.relationship('BfUserCoin', backref='user',
                                lazy='dynamic')
    b_invit = db.relationship('BfInvit', backref='invit_user',
                                lazy='dynamic')

    user_coin = db.relationship('BfUserCoin', backref='coin_user',uselist=False)
    betting = db.relationship('QhBetting', backref='betting_user')


class BfUserCoin(db.Model):
    __bind_key__ = 'jys'
    __tablename__='bf_user_coin'
    id=db.Column(db.Integer,primary_key=True,autoincrement=True,onupdate=0)
    userid=db.Column(db.Integer,db.ForeignKey('bf_user.id'))
    btc = db.Column(db.Numeric(20, 10), default=0, comment='btc余额',nullable=False)
    btcd = db.Column(db.Numeric(20, 8), default=0, comment='btc冻结金额', nullable=False)
    btcb = db.Column(db.String(200), nullable=False, comment="btc地址",default='0')
    ltc = db.Column(db.Numeric(20, 8), default=0, comment='ltc余额', nullable=False)
    ltcd = db.Column(db.Numeric(20,8 ), default=0, comment='ltc冻结金额', nullable=False)
    ltcb = db.Column(db.String(200), nullable=False, comment="ltc地址",default='0')
    eth = db.Column(db.Numeric(20, 10), default=0, comment='eth余额', nullable=False)
    ethd = db.Column(db.Numeric(20, 8), default=0, comment='eth冻结金额', nullable=False)
    ethb = db.Column(db.String(200), nullable=False, comment="eth地址",default='0')
    cusd = db.Column(db.Numeric(20, 8), default=0, comment='cusd余额', nullable=False)
    cusdd = db.Column(db.Numeric(20, 8), default=0, comment='cusdd冻结金额', nullable=False)
    usdt = db.Column(db.Numeric(20, 8), default=0, comment='usdt余额', nullable=False)
    usdtd = db.Column(db.Numeric(20, 8), default=0, comment='usdt冻结金额', nullable=False)
    usdtb = db.Column(db.String(200), nullable=False, comment="usdt地址", default='0')
    bch = db.Column(db.Numeric(20, 8), default=0, comment='bch余额', nullable=False)
    bchd = db.Column(db.Numeric(20, 8), default=0, comment='bchd冻结金额', nullable=False)
    bchb = db.Column(db.String(200), nullable=False, comment="bchb地址", default='0')

class BfInvit(db.Model):
    __bind_key__ = 'jys'
    __tablename__ = 'bf_invit'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, onupdate=0)
    userid = db.Column(db.Integer, db.ForeignKey('bf_user.id'))
    invit = db.Column(db.Integer)
    name = db.Column(db.SmallInteger)
    type = db.Column(db.Integer)
    num = db.Column(db.Numeric(20, 8), default=0, comment='ltc余额', nullable=False)
    mum = db.Column(db.Numeric(20, 8), default=0, comment='ltc余额', nullable=False)
    fee = db.Column(db.Numeric(20, 8), default=0, comment='ltc冻结金额', nullable=False)
    sort =db.Column(db.Integer)
    addtime = db.Column(db.Integer)
    endtime = db.Column(db.Integer)
    status = db.Column(db.SmallInteger)
    buysell = db.Column(db.SmallInteger)
    orderno = db.Column(db.String(100),  comment="bchb地址")

class TwBtc(db.Model):
    __bind_key__ = 'jys'
    __tablename__ = 'tw_btc'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, onupdate=0)
    name = db.Column(db.String(20))
    name_yw = db.Column(db.String(20))
    short_name = db.Column(db.String(20))
    price = db.Column(db.Numeric(30, 8))
    updatetime =db.Column(db.Integer)

class TwEth(db.Model):
    __bind_key__ = 'jys'
    __tablename__ = 'tw_eth'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, onupdate=0)
    name = db.Column(db.String(20))
    name_yw = db.Column(db.String(20))
    short_name = db.Column(db.String(20))
    price = db.Column(db.Numeric(30, 8))
    updatetime =db.Column(db.Integer)


class TwMyzr(db.Model):
    __bind_key__ = 'jys'
    __tablename__ = 'tw_myzr'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, onupdate=0)
    user_id =  db.Column(db.Integer, db.ForeignKey('bf_user.id'))
    username = db.Column(db.String(200))
    coinnanme = db.Column(db.String(200))
    txid = db.Column(db.String(200))
    num = db.Column(db.Numeric(20,10))
    mum = db.Column(db.Numeric(20,10))
    fee = db.Column(db.Numeric(20,10))
    sort = db.Column(db.Integer)
    addtime = db.Column(db.Integer)
    endtime = db.Column(db.Integer)
    status = db.Column(db.Integer)
    from_user = db.Column(db.SmallInteger)


